let notices = []
/**
 * @param {Object} name
 * @param {Object} receiver
 * @param {Object} observer
 */
function add(name, receiver, observer) {
	let notice = {
		name,
		receiver,
		observer
	}
	notices.push(notice)
}
/**
 * @param {Object} name
 * @param {Object} observer
 */
function remove(name, observer) {
	for (let i = 0; i < notices.length; i++) {
		let notice = notices[i]
		if (notice.name == name) {
			if (notice.observer == observer) {
				notices.splice(i, 1)
				return
			}
		}
	}
}
/**
 * @param {Object} name
 * @param {Object} info
 */
function post(name, info) {
	if (notices.length == 0) {
		console.log("err没有注册通知");
		return
	}
	for (let i = 0; i < notices.length; i++) {
		let notice = notices[i]
		if (notice.name == name) {
			notice.receiver(info)
		}
	}
}


module.exports = {
	add,
	remove,
	post
}